
var _sel = null ;
function docancel()
{
	divobj = document.getElementById("uploadpic");
	divobj.style.display = "none"; 
}
function $get(i)
{
	return document.getElementById(i);
}
var imgNums = 0;
var flag    = "imgs_";
var path    = "";
function doinsert()
{
	inputvalue = $get(flag+imgNums).value;
	if(inputvalue=="")
	{
		alert("没有选择任何图片！");
		return false ;
	}
	else
	{
		path       = path+inputvalue+"," ;
		var oEditor = FCKeditorAPI.GetInstance('fckeditor1') ;
		oEditor.EditorDocument.focus();
		if(_sel)
		{
			//oEditor.EditorDocument.selection=FCKEditorExt._sel;
			_sel.select();
		}
		oEditor.InsertHtml( '<img  src="'+$get(flag+imgNums).value+'" alt="'+flag+imgNums+'"/>');		
		var inputobj=$get(flag+imgNums);
		inputobj.style.display = "none";
		imgNums+=1;
		inputobj=document.createElement('<input type="file" id="imgs_'+imgNums+'" name="uploadImg[]" size="25" />');
		$get('imgfiles').appendChild(inputobj);
		docancel();
	}
	
}
function shownetpid()
{
	$get("netPicDiv").style.display = "";
	$get("localPicDiv").style.display = "none";
}
function showlocalpic()
{
	$get("localPicDiv").style.display = "block";
	$get("netPicDiv").style.display = "none";
}
function doinserturlpic()
{
	piculr = $get("picurl").value ;
	if(_sel)
		{
			//oEditor.EditorDocument.selection=FCKEditorExt._sel;
			_sel.select();
		}
	var oEditor = FCKeditorAPI.GetInstance('fckeditor1') ;
	oEditor.InsertHtml( '<img  src="'+piculr+'" alt="'+piculr+'"/>');
	$get("picurl").value = "http://";
	docancel();
}
function createpicdiv()
{
	 var str = '<div id="uploadpic" style="display:none;position:absolute;width:360; margin:5px auto; border:#0000FF 2px solid; background:#FFFFFF;"><div id="header" style="background:#d7d79f; width:inherit; padding:3px; font-size:13px; font-weight:bold;">插入图片</div><div id="choosetype" style="padding:5px 0px 5px 0px;font-size:13px;background-color:f1f1e3;"><input type="radio" class="radio" name="pictype" value="" checked="checked"  onclick="showlocalpic()"/>本地图片 &nbsp;&nbsp;<input type="radio" class="radio" name="pictype"  onclick="shownetpid()" />网络图片</div><div id="netPicDiv" style="display:none;background-color:f1f1e3;"><div style="padding:10px ; font-size:13px" id="chooseDiv">图片地址:<span id="imgpath" style="padding:10px inherit;" ><input type="text" id="picurl" name="uploadImg[]" size="35" style="height:20px" value="http://"></span></div><div style="text-align:center;padding:5px"><input type="button" style="background:#c7c78f;border: #737357 1px solid;color: #3b3b1f;" name="surebutton" value="确定" onClick="doinserturlpic()">&nbsp;&nbsp;&nbsp;<input type="button" style="background:#c7c78f;border: #737357 1px solid;color: #3b3b1f;" name="cancelbutton" value="取消" onClick="docancel()" ></div></div><div id="localPicDiv" style="display:block;background-color:f1f1e3;"><div style="padding:10px ; font-size:13px" id="chooseDiv">选择图片:<span id="imgfiles" style="padding:15px inherit;" ><input type="file" id="imgs_0" name="uploadImg[]" size="25"></span></div><div style="text-align:center;padding:5px"><input type="button" name="surebutton" value="确定" style="background:#c7c78f;border: #737357 1px solid;color: #3b3b1f;" onClick="doinsert()">&nbsp;&nbsp;&nbsp;<input type="button" name="cancelbutton" value="取消" style="background:#c7c78f;border: #737357 1px solid;color: #3b3b1f;" onClick="docancel()" ></div></div></div>';	
document.write(str);
}


function addlength()
{
	var oEditor = FCKeditorAPI.GetInstance('fckeditor1') ;
		oEditor.TemplatesXmlPath= "fcktemplates1.xml";	
	alert(oEditor.TemplatesXmlPath);
}

var _getPosition = function(o)
{
	var p1= o.offsetLeft,p2= o.offsetTop;
	do 
	{
		o = o.offsetParent;
		p1 += o.offsetLeft;
		p2 += o.offsetTop;
	}
		while( o.tagName.toLowerCase()!="body");
		return {"x":p1,"y":p2};
};
var show = function (sel,pos)
{
	_sel = sel ;
	objdiv = document.getElementById("uploadpic");
	objdiv.style.display = "";
	objdiv.style.posLeft = pos.x+180 ;
	objdiv.style.posTop  = pos.y+50 ;	
}
